package data;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.json.JSONException;
import org.json.JSONObject;

import com.PassByUtiles;
import com.google.android.maps.GeoPoint;

public class PassByItem implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	public String id;
	public String content;
	public Date creatdTime;
	public User user;
	public int comments;
	public GeoPoint location;
	
	public static PassByItem decode(JSONObject item)
	{
		PassByItem result = null;
		try {
			result = new PassByItem();
			result.id = item.getString("id");
			result.content = item.getString("content");
			//2012-01-07 15:48:29.841000
			DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			result.creatdTime = df.parse(item.getString("created_time"));
			result.comments = item.getInt("comments");
			result.location = PassByUtiles.decodeGeoPt(item.getString("location"));
		} catch (JSONException e) {
			e.printStackTrace();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return result;
	}
}
